<?php

namespace App\Repositories\Cart;
use Illuminate\Support\Facades\DB;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\Cart\cartRepository;
use App\Models\Cart;

/**
 * Class CartRepositoryEloquent.
 *
 * @package namespace App\Repositories;
 */
class CartRepositoryEloquent extends BaseRepository implements CartRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return Cart::class;
    }

    public function getByUserId($userId){
        return DB::table('cart as ca')
            ->leftJoin('goods as g','ca.goods_id','=','g.goods_id')
            ->where('user_id',$userId)
            ->get();
    }

    public function addGoods(array $GoodsInfo){
        return DB::table('cart')->insertGetId($GoodsInfo);
    }

    public function updateGoods(array $GoodsInfo, int $recId){
        return DB::table('cart')->where('rec_id',$recId)->update($GoodsInfo);
    }

    public function deleteGoods(int $recId){
        return DB::table('cart')->where('rec_id',$recId)->delete();
    }


    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }
    
}
